//
//  OneCustomView.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/5.
//  Copyright © 2017年 金橙云. All rights reserved.
//
#define X_WIDTH (self.frame.size.width)
#import "OneCustomView.h"

#import "TodoHttpManager.h"

@implementation OneCustomView


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        _manager = [TodoHttpManager sharedManager];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDManagerFirstSales:) name:TDManagerFirstSales object:nil];
        [_manager userManagerFirstSalesDynamic];
        UIView *oneView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, X_WIDTH, 30)];
        oneView.backgroundColor = [UIColor orangeColor];
        [self addSubview:oneView];
        
        NSInteger a = X_WIDTH/3;
        
        
        _oneLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, 100, 20)];
       // oneLab.text = [NSString stringWithFormat:@"本月认筹: %@",_bigDic[@"day_rc"]];
        
        _oneLab.font= [UIFont systemFontOfSize:14];
        _oneLab.textColor= [UIColor whiteColor];
        [self addSubview:_oneLab];
        
        UILabel *lineLab = [[UILabel alloc] init];
        lineLab.backgroundColor = [UIColor whiteColor];
        [self addSubview:lineLab];
        [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(1, 30));
            make.left.equalTo(oneView.mas_left).offset(a);
        }];
        
        _twoLab = [[UILabel alloc] init];
       // _twoLab.text = @"本月认筹:12";
        _twoLab.font= [UIFont systemFontOfSize:14];
        _twoLab.textColor= [UIColor whiteColor];
        [self addSubview:_twoLab];
        [_twoLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(100, 20));
            make.left.equalTo(lineLab.mas_right).offset(20);
            make.top.equalTo(oneView.mas_top).offset(5);
        }];
        
        
        UILabel *lineLabA = [[UILabel alloc] init];
        lineLabA.backgroundColor = [UIColor whiteColor];
        [self addSubview:lineLabA];
        [lineLabA mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(1, 30));
            make.left.equalTo(oneView.mas_right).offset(-a);
        }];
        
        
        _threeLab = [[UILabel alloc] init];
        //_threeLab.text = @"累计认筹:12";
        _threeLab.font= [UIFont systemFontOfSize:14];
        _threeLab.textColor= [UIColor whiteColor];
        [self addSubview:_threeLab];
        [_threeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(100, 20));
            make.left.equalTo(lineLabA.mas_right).offset(20);
            make.top.equalTo(oneView.mas_top).offset(5);
        }];
        
        
      
         NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
        if ([IDA isEqualToString:@"2"])
        {
            UILabel *titLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 35, 100, 25)];
            titLab.text = @"本月任务";
            titLab.font= [UIFont systemFontOfSize:14];
            titLab.textColor= [UIColor blackColor];
            [self addSubview:titLab];
            
            UILabel *hengLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 65, X_WIDTH-10*2, 0.5)];
            hengLab.backgroundColor = [UIColor grayColor];
            [self addSubview:hengLab];
            
            _nianLab = [[UILabel alloc] init];
            _nianLab.textColor = [UIColor grayColor];
            _nianLab.font= [UIFont systemFontOfSize:12];
            _nianLab.text = @"2017年04月 |";
            [self addSubview:_nianLab];
            [_nianLab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(80, 20));
                make.left.equalTo(self.mas_left).offset(10);
                make.top.equalTo(hengLab.mas_top).offset(8);
                
            }];
            
            _wanLab = [[UILabel alloc] init];
            _wanLab.textColor = [UIColor colorWithHexString:@"#0FD4C9"];
            _wanLab.font= [UIFont systemFontOfSize:12];
            _wanLab.text = @"563/";
            //_wanLab.backgroundColor = [UIColor redColor];
            _wanLab.textAlignment = NSTextAlignmentRight;
            [self addSubview:_wanLab];
            [_wanLab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(50, 20));
                make.left.equalTo(_nianLab.mas_right).offset(5);
                make.top.equalTo(hengLab.mas_top).offset(8);
                
            }];
            
            _allLab = [[UILabel alloc] init];
            _allLab.textColor = [UIColor grayColor];
            _allLab.font= [UIFont systemFontOfSize:12];
            _allLab.text = @"5630.00万";
            //_wanLab.backgroundColor = [UIColor redColor];
            _allLab.textAlignment = NSTextAlignmentLeft;
            [self addSubview:_allLab];
            [_allLab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(80, 20));
                make.left.equalTo(_wanLab.mas_right);
                make.top.equalTo(hengLab.mas_top).offset(8);
                
            }];
            
            
            _biLab = [[UILabel alloc] init];
            _biLab.textColor = [UIColor grayColor];
            _biLab.font= [UIFont systemFontOfSize:12];
            _biLab.text = @"完成比例:47%";
            //_wanLab.backgroundColor = [UIColor redColor];
            _biLab.textAlignment = NSTextAlignmentRight;
            [self addSubview:_biLab];
            [_biLab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(100, 20));
                make.right.equalTo(self.mas_right).offset(-10);
                make.top.equalTo(hengLab.mas_top).offset(8);
                
            }];

            _proView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
            [_proView setProgress:0.7 animated:NO];
            //设置轨道颜色
            _proView.trackTintColor = [UIColor colorWithHexString:@"#E3E3E3"];
            //设置进度颜色
            _proView.progressTintColor = [UIColor colorWithHexString:@"#0FD4C9"];
            _proView.layer.cornerRadius = 8.0f;
            _proView.layer.masksToBounds = YES;
            [self addSubview:_proView];
            [_proView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(self.frame.size.width-15*2, 10.0f));
                make.left.equalTo(self.mas_left).offset(15);
                make.top.equalTo(lineLabA.mas_bottom).offset(70);
            }];
            

        }
        
        
        
        _oneDic = [NSMutableDictionary dictionaryWithCapacity:0];
        
        
        
        
        
        
        
        
    }
    return self;
}

-(void)didTDManagerFirstSales:(NSNotification *)notifi
{
    if (notifi.object != 0)
    {
        _oneDic = [notifi.object objectForKey:@"data"];
        
        
        
       // NSLog(@"111======%@",_oneDic[@"day_rc"]);
        _oneLab.text = [NSString stringWithFormat:@"今日认筹: %@",_oneDic[@"day_rc"]];
        _twoLab.text = [NSString stringWithFormat:@"本月认筹: %@",_oneDic[@"month_rc"]];
        _threeLab.text = [NSString stringWithFormat:@"累计认筹: %@",_oneDic[@"all_rc"]];
        _nianLab.text = [NSString stringWithFormat:@"%@|",_oneDic[@"riqi"]];
        _wanLab.text =[NSString stringWithFormat:@"%@",_oneDic[@"finish_money"]];
        _allLab.text = [NSString stringWithFormat:@"/%@",_oneDic[@"all_money"]];
        NSString *biStr = [NSString stringWithFormat:@"%@",_oneDic[@"bl"]];
        _biLab.text =[NSString stringWithFormat:@"完成比例 :%@ %%",_oneDic[@"bl"]];
        
      //  NSLog(@"biStr %@",biStr);
        [_proView setProgress:[biStr intValue]*0.01 animated:NO];
       
        
    }
    
       [self.delegate setDelegate:_oneDic];
}




-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDManagerFirstSales object:nil];
}





@end
